package com.hmsg.health.controller.admin;


import com.hmsg.health.bean.Dto.SorderDos;
import com.hmsg.health.bean.Dto.SorderDto;
import com.hmsg.health.bean.domain.BannerDo;
import com.hmsg.health.bean.enums.StatusCode;
import com.hmsg.health.dao.AdminSorderDao;
import com.hmsg.health.param.ResponseResult;
import com.hmsg.health.security.IgnoreSecurity;
import com.hmsg.health.service.admin.AdminSorderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Api(value = "运营系统充值记录相关", tags = { "运营系统充值记录相关" })
@Slf4j
@Controller
@RequestMapping("/order")
public class AdminOrderController {
    @Autowired
    private AdminSorderService adminSorderService;
    @Autowired
    private AdminSorderDao adminSorderDao;


    @GetMapping("/list")
    @ApiOperation(value="运营系统充值记录相关", notes="运营系统充值记录相关" ,httpMethod="GET")
    @ResponseBody
    @IgnoreSecurity
    public ResponseResult<SorderDos> queryList(@RequestParam(value = "phone",required = false) String phone,
                                               @RequestParam(value = "time", required = false) String time,
                                               @RequestParam(value = "pageNo") Integer pageNo,
                                                @RequestParam(value = "pageSize") Integer pageSize) {
        Integer firstResult = (pageNo-1)*pageSize;
        Integer maxResult =pageSize;

        int totalpages;//总页数

        int total=adminSorderDao.countAll(phone,time);
        totalpages=   total/pageSize;
        if(total% pageSize !=0){
            totalpages++;
        }

        List<SorderDto> sorderDtoList= adminSorderService.findAll(phone,time,firstResult,maxResult);
        SorderDos sorderDos=new SorderDos();
        if(sorderDtoList != null && sorderDtoList.size()>0){

            sorderDos.setSorderDtoList(sorderDtoList);
            sorderDos.setTotalpages(totalpages);
            return new ResponseResult<SorderDos>(StatusCode.SYSTEM_SUCCESS, sorderDos);
        }
        return new ResponseResult<SorderDos>(StatusCode.SYSTEM_SUCCESS, sorderDos);
    }
}
